<?php

namespace app\admin\controller;
use think\Controller;
use app\admin\model\ManageModel;

class Management extends Controller
{
  private $Model;

  public function __construct(){
      $this ->Model = new ManageModel();
  }

  public function select(){//获取职位信息和分页打印
    $page = getPost()['page'];//获取当前sql开始下标
    $res = $this->Model->select($page);
    return res(1000,'获取成功',$res);
  }
  public function getMenu(){//获取菜单信息
    $res = $this->Model->getMenu();
    return res(1000,'获取成功',$res);
  }
  public function addManage(){//添加职位
    $name = getPost()['name'];
    $check = $this->Model->onlyName($name);
    if(count($check)==0){
      $res = $this->Model->addManage($name);
      if($res){
        return res(1000,'添加成功,请给该职位添加权限');
      }else{
        return res(1001,'添加失败');
      }
    }else{
      return res(1002,"职位重复");
    }
    
  }
  public function changeManage(){//修改职位名称
    $name = getPost()['nameText'];
    $xiaBiao = getPost()['xiaBiao'];
    $check = $this->Model->onlyName($name);
    if(count($check)==0){
      $res = $this->Model->changeManage($name,$xiaBiao);
      if($res){
        return res(1000,"修改成功");
      }else{
        return res(1001,"修改失败");
      }
    }else{
      return res(1002,"职位名称重复");
    }
  }
  public function del(){//删除职位
    $jid = getPost()['jid'];
    $res = $this->Model->del($jid);
    if($res){
      return res(1000,'删除成功');
    }else{
      return res(1001,'删除失败');
    }
  }
  public function getOfMenu(){//获取对应职位菜单
    $jid = getPost()['jid'];
    $res = $this->Model->getOfMenu($jid);
    if($res){
      return res(1000,"获取成功",$res["menu_id"]);
    }else{
      return res(1001,"数据错误");
    }
  }
  public function changeId(){
    $jid = getPost()['id'];
    $menu_id = getPost()['menu'];
    $res = $this->Model->changeId($jid,$menu_id);
    if($res){
      return res(1000,"修改成功");
    }else{
      return res(1001,"修改失败");
    }
  }
}